package com.neusoft.classses;

public class TestArray {

	public static void main(String[] args ) {
		//初始化数及遍历输出
		testArray01();
		//检测各种类型数组的默认值
		testArray02();
		//二维数组声明及初始化的几种方式
		twoDimensionArray();
		
		
		
	}
	
	/*
	 * 定义二维数组并遍历
	 * 
	 */
	private static void twoDimensionArray() {
		//声明及初始化1
		int[][] arr1 = new int[2][3];
		//声明及初始化2
		int[][] arr2=new int[][]{{1,2,3},{2,3,4}};
		//声明及初始化3
		int[][] arr3= {{3,4,5},{5,6,7}};
		//声明及初始化4
		int[][] arr4=new int[3][];
		arr4[0]= new int[5];
		arr4[1]=new int[] {3,2,1};
		arr4[2]=new int[] {2,3,4,5};
		
		//for循环遍历
		for(int i=0;i<arr4.length;i++) {
			for(int j=0;j<arr4[i].length;j++) {
				System.out.print(" "+arr4[i][j]);
			}
			System.out.println();
		}
		
		//用foreach遍历
		
		
		
	}
	
	
	
	
	
	
	
	
	
	
	
	//定义几种类型的数组， 查看默认值
	private static void testArray02() {
		//定义整型数组
		System.out.println("整型数组======");
		int[] arrayInt = new int[5];
		for (int i : arrayInt) {
			System.out.println(i+" ");
		}
		
		//定义字符型数组
		System.out.println("字符型数组======");
		char[] arrayChar =new char[5];
		for (char c : arrayChar) {
			System.out.println(c+" ");
		}
		//定义字节型数组
		System.out.println("byte型数组======");
		byte[] arrayByte = new byte[5];
		for (byte b : arrayByte) {
			System.out.println(b+" ");
		}
		//定义short型数组
		System.out.println("short型数组======");
		short[] arrayShort=new short[5];
		for (short s : arrayShort) {
			System.out.println(s+" ");
		}
		//定义long型数组
		System.out.println("long型数组======");
		long[] arrayLong = new long[5];
		for (long l : arrayLong) {
			System.out.println(l+" ");
		}
		//定义布尔型数组
		System.out.println("布尔型数组======");
		boolean[] arraybool = new boolean[5];
		for (boolean b : arraybool) {
			System.out.println(b+" ");
		}
		//定义float型数组
		System.out.println("单精度浮点型数组======");
		float[] arrayFloat = new float[5];
		for (int i=0 ;i<5;i++) {
			System.out.println(arrayFloat[i]);
		}
		
		//定义double型数组
		System.out.println("双精度浮点型型数组======");
		double[] arrayDouble = new double[5];
		
		for (double d : arrayDouble) {
			System.out.println(d+" ");
		}
		
		
		
		
				
		
	}
	
	
	
	
	
	
	
	

	//定义数组并遍历
	private static void testArray01() {
		//定义一个数组
		int[] array01=new int[5];
		//给数组中的元素赋值
		for(int i=0;i<array01.length;i++) {
			array01[i]=2*i+3;
		}
		//遍历输出
		for(int i=0;i<array01.length;i++) {
			System.out.print(array01[i]+" ");
		}
		//换行
		System.out.println();
	}



}
